package com.server.questionbank.snframe.service.UsersService.Impl;

import com.server.questionbank.snframe.domain.ResDTO.ResponseResult;
import com.server.questionbank.snframe.mapper.TUserMapper;
import com.server.questionbank.snframe.service.UsersService.LoginsService;
import com.server.questionbank.snframe.service.UsersService.UsersService;
import com.server.questionbank.snframe.util.JWT.JwtTokenProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;

@Service
public class LoginsServiceImpl implements LoginsService {

    @Autowired
    private UsersService usersService;

    // 手机号登录
    @Override
    public ResponseResult<Long> phoneLogin(String phoneNumber, String password) {
        if(phoneNumber == null || password == null) return ResponseResult.error("手机号或密码不能为空！");
        Long userId = usersService.selectUserByPhoneNumber(phoneNumber, JwtTokenProvider.sha256(password));
        if(userId == null || userId <= 0) return ResponseResult.error("手机号或密码错误！");
        return ResponseResult.success(userId);
    }
}
